package com.zkr.kfsz.conterllor;


import com.zkr.kfsz.model.KFSZAddVo;
import com.zkr.kfsz.model.KFSZSelectVo;
import com.zkr.kfsz.model.KFSZUpdateStatus;
import com.zkr.kfsz.model.KFSZUpdateVo;
import com.zkr.kfsz.service.KFSZService;
import com.zkr.util.ResultBuilderVo;
import com.zkr.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by lenovo on 2021/1/13.
 */
@RestController
@CrossOrigin
public class KFSZConterllor {

     @Autowired
    private KFSZService kfszService;


    /**
     * 分页
     */

    @PostMapping("warehouse/queryPage")
    public ResultVo queryPage(@RequestBody KFSZSelectVo kfszSelectVo){
        return kfszService.queryPage(kfszSelectVo);
    }





    /**
     * 添加
     */
    @PostMapping("warehouse/add")
    public ResultVo add(@RequestBody @Valid KFSZAddVo kfszAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kfszService.add(kfszAddVo);
    }




    /**
     * 修改启用禁用接口
     * @param kfszUpdateStatus
     * @param bindingResult
     * @return
     */

    @PostMapping("warehouse/updateStatus")
    public ResultVo updateStatus(@RequestBody @Valid KFSZUpdateStatus kfszUpdateStatus, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kfszService.updateStatus(kfszUpdateStatus);
    }


    /**
     * 库房标识下拉框
     */
    @GetMapping("warehouse/queryWarehouseTagList")
    public ResultVo kF(){
        return kfszService.queryKF();
    }
     /**
     * 修改
     */
    @PostMapping("warehouse/update")
    public ResultVo update(@RequestBody @Valid KFSZUpdateVo kfszUpdateVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultBuilderVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return kfszService.update(kfszUpdateVo);
    }
}








